package com.example.list.lazyload;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.example.list.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class LazyLoadActivity extends AppCompatActivity {

    String[] title = {"昨天", "今天", "明天"};
    ArrayList<Fragment> fragments=new ArrayList<>();
    ArrayList<String> titles=new ArrayList<>();
    private ViewPager vp_lazy;
    private TabLayout tab_lazy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lazy_load);
        tab_lazy = (TabLayout) findViewById(R.id.tab_lazy);
        vp_lazy = (ViewPager) findViewById(R.id.vp_lazy);
        for (int i = 0; i < title.length; i++) {

            titles.add(title[i]);
        }
//        fragments.add(new FragmentX());
//        fragments.add(new FragmentX2());
//        fragments.add(new FragmentX3());

        fragments.add(new Fk1());
        fragments.add(new Fk2());
        fragments.add(new Fk3());

        FPAdater fpAdater = new FPAdater(getSupportFragmentManager(), fragments, titles);
        vp_lazy.setAdapter(fpAdater);
        tab_lazy.setupWithViewPager(vp_lazy);
    }
}